/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.raspberrypi.gpio;

import java.util.logging.Logger;

/**
 * <b>(Component)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/2/14
 */
@SuppressWarnings("unused")
public class Component {
    /** Logger instance */
    private final Logger logger = Logger.getLogger(getClass().getName());

    protected void logInfo(String msg) {
        logger.info(() -> msg);
    }

    protected void logError(String msg) {
        logger.severe(() -> msg);
    }

    protected void logConfig(String msg) {
        logger.config(() -> msg);
    }

    protected void logDebug(String msg) {
        logger.fine(() -> msg);
    }

    /**
     * Utility function to sleep for the specified amount of milliseconds.
     * An {@link InterruptedException} will be caught and ignored while setting the interrupt flag again.
     *
     * @param milliseconds Time in milliseconds to sleep
     */
    void delay(long milliseconds) {
        try {
            Thread.sleep(milliseconds);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
